package com.ruyuan.eshop.common.dao.impl;

import com.baomidou.mybatisplus.extension.conditions.update.UpdateChainWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruyuan.eshop.common.dao.TradeDAO;
import com.ruyuan.eshop.common.domain.entity.TradeDO;
import com.ruyuan.eshop.common.enums.OrderStatusEnum;
import com.ruyuan.eshop.common.enums.TradeStatusEnum;
import com.ruyuan.eshop.common.mapper.TradeMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

/**
 * 交易mapper
 * @author pwd
 * @version 1.0
 */
@Repository
public class TradeDAOImpl extends ServiceImpl<TradeMapper, TradeDO> implements TradeDAO {

    @Autowired
    private TradeMapper tradeMapper;

    @Override
    public void updateTradeStatus(String tradeSn) {
        new UpdateChainWrapper<>(tradeMapper)
                //设置交易状态
                .set("trade_status", TradeStatusEnum.PAID_OFF.value())
                //按交易编号修改
                .eq("trade_sn", tradeSn)
                //提交修改
                .update();
    }

    @Override
    public boolean updateTradeStatus(String sn, OrderStatusEnum orderStatus) {
        new UpdateChainWrapper<>(tradeMapper)
                //设置订单状态
                .set("trade_status", orderStatus.value())
                //按订单编号修改
                .eq("trade_sn", sn)
                //提交修改
                .update();
        return true;
    }
}
